<template>
	<view class="main">		
		<view class="nxc" v-if="dataList">	
			<view class="nxc-item" v-for="(item, index) in dataList" :key="item.id"  @tap="check(index)" >
				<view class="item">
					<view class="content">	
						{{item.nickname}}({{item.allow == 0?'不可选择':(item.tag != null?item.tag:'')}})	
					</view>	
					<view class="action" v-if="item.ischecked == 1">						
						<text class="wlIcon-31xuanze" style="float: right;margin-top: 3px;color: green;font-size: 20px;"></text>						
					</view>				
				</view>					
			</view>
		</view>
		<!-- 空 -->
		<view v-if="dataList.length == 0">
			<wanl-empty src="ticket_default3x" text="你还没有下线"/>
		</view>
		<view style="height: 60px;"></view>
		<view class="" style="<!-- position: fixed;bottom: 5px;left: 0; -->">
			<button v-if="loading" style="width: 90%;  margin-left: 5%;" class="cu-btn round lg bg-gradual-orange margin-lr-bj">
				<text class="wlIcon-jiazai wlIconfont-spin margin-right-xs"></text> 提交中...
			</button>
			<button v-else  style="width: 90%;  margin-left: 5%;"   @tap="confirm" class="cu-btn round lg bg-gradual-orange margin-lr-bj"> 保存并返回 </button>
		</view>
		
		
	
	</view>
</template>

<script>
 
export default {
	data() {
		return {
			id:0,
			dataList: [],
			loading:false
		};
	},
	onLoad(option) {
		this.id = option.id;
		this.loadData();
	},
	
	methods: {
		async loadData(type) {
			let data = {
					page: this.current_page
				};
			if(type)data.type = type;
			await uni.request({
				url: '/wanlshop/user/getOneOffines',
				method: 'POST',
				data: data,
				success: res => {					
					this.dataList = res.data.data;					
				}
			});
		},
		check(index){
			if(this.dataList[index].allow == 0){
				this.$wanlshop.msg('该下线为不可被选择为员工');
				return false;
			}
			if(this.dataList[index].ischecked == 1){
				this.dataList[index].ischecked = 0
			}else{
				this.dataList[index].ischecked = 1
			}
			this.$forceUpdate();
		},
		confirm() {
			let ids = [];
			
			this.dataList.forEach(item => {					
				if(item.ischecked == 1){					
					ids.push(item.id);
				}				
			})
			ids = ids.join(',');
			
			this.loading = true;
			uni.request({
				url: '/wanlshop/user/editWorker',
				method: 'POST',
				data: {ids:ids,id:this.id},
				success: res => {					
					this.$wanlshop.prePage().refreshList();					
					this.$wanlshop.back(1);
				}
			});
		}
	}
};
</script>

<style>
	.main{
		width: 100%;height: 100#;background-color: #E3E8F7;margin-top: -30rpx;padding:24rpx;padding-top: 60rpx;
	}
	.nxc-item .item{
		margin: 20rpx 0;
		background-color: white;
		border-radius: 6px;
		padding: 10rpx;
		font-size: 32rpx;
		position: relative;
		
	}
	.nxc-item .item .content{
		border-left: 2px solid red;
		line-height: 40rpx;
		padding: 18rpx 20rpx;
	}
	.nxc-item .item .action{
		position: absolute;
		right: 10px;
		top: 30rpx;
	}
	
	
</style>
